package com.googlecode.nacl_optimizer.elf.headers;

import com.googlecode.nacl_optimizer.elf.types.Elf32Half;


public enum FileTypeField {
    ET_NONE( new Elf32Half(0), "No file type"),
    ET_REL( new Elf32Half(1), "Relocatable file"),
    ET_EXEC( new Elf32Half(2), "Executable file"),
    ET_DYN( new Elf32Half(3), "Shared object file"),
    ET_CORE( new Elf32Half(4), "Core file"),
    ET_LOPROC( new Elf32Half(0xff00), "Processor-specific"),
    ET_HIPROC( new Elf32Half(0xffff), "Processor-specific");

    private String text;
    private int v;
    
    private FileTypeField(Elf32Half v, String text) {
        this.v=v.getInteger();
        this.text=text;
    }

    public static FileTypeField getType(Elf32Half half) {
        for(FileTypeField type: FileTypeField.values()) {
            if(half.getInteger().equals(type.v)) {
                return type;
            }
        }
        throw new IllegalArgumentException();
    }

    @Override
    public String toString() {
        return this.text;
    }
}
